namespace SeataNet.Core.RPC
{
    /// <summary>
    /// RPC客户端接口
    /// </summary>
    public interface IRpcClient
    {
        /// <summary>
        /// 获取连接状态
        /// </summary>
        bool IsConnected { get; }

        /// <summary>
        /// 发送请求并获取响应
        /// </summary>
        /// <typeparam name="TRequest">请求类型</typeparam>
        /// <typeparam name="TResponse">响应类型</typeparam>
        /// <param name="request">请求对象</param>
        /// <param name="timeout">超时时间（毫秒）</param>
        /// <returns>响应对象</returns>
        Task<TResponse> SendAsync<TRequest, TResponse>(TRequest request, int timeout = 30000) where TRequest : class where TResponse : class;

        /// <summary>
        /// 发送请求并获取响应（支持取消令牌）
        /// </summary>
        /// <typeparam name="TRequest">请求类型</typeparam>
        /// <typeparam name="TResponse">响应类型</typeparam>
        /// <param name="request">请求对象</param>
        /// <param name="cancellationToken">取消令牌</param>
        /// <returns>响应对象</returns>
        Task<TResponse> SendAsync<TRequest, TResponse>(TRequest request, CancellationToken cancellationToken) where TRequest : class where TResponse : class;

        /// <summary>
        /// 发送单向请求（不需要响应）
        /// </summary>
        /// <typeparam name="TRequest">请求类型</typeparam>
        /// <param name="request">请求对象</param>
        /// <returns>发送结果</returns>
        Task<bool> SendOnewayAsync<TRequest>(TRequest request) where TRequest : class;

        /// <summary>
        /// 发送消息到指定地址
        /// </summary>
        /// <typeparam name="TMessage">消息类型</typeparam>
        /// <param name="address">目标地址</param>
        /// <param name="message">消息对象</param>
        /// <returns>发送结果</returns>
        Task SendMessageAsync<TMessage>(string address, TMessage message) where TMessage : class;

        /// <summary>
        /// 发送消息并获取响应
        /// </summary>
        /// <typeparam name="TResponse">响应类型</typeparam>
        /// <param name="address">目标地址</param>
        /// <param name="request">请求对象</param>
        /// <returns>响应对象</returns>
        Task<TResponse> SendMessageAsync<TResponse>(string address, object request) where TResponse : class;

        /// <summary>
        /// 初始化客户端
        /// </summary>
        /// <param name="serverAddress">服务器地址</param>
        /// <param name="applicationId">应用ID</param>
        /// <param name="transactionServiceGroup">事务服务组</param>
        /// <returns>初始化结果</returns>
        Task<bool> InitializeAsync(string serverAddress, string applicationId, string transactionServiceGroup);
        
        /// <summary>
        /// 销毁客户端
        /// </summary>
        /// <returns>销毁结果</returns>
        Task<bool> DestroyAsync();
        
        /// <summary>
        /// 是否已初始化
        /// </summary>
        bool IsInitialized { get; }
    }
}